package api

import (
	"fmt"
	"github.com/gin-gonic/gin"
	"github.com/huifurepo/bspay-go-sdk/BsPaySdk"
	"strconv"
	"time"
)

func (P *HUIFUPAY) Pay(c *gin.Context) {
	dgSDK, err := BsPaySdk.NewBsPay(false, "./config/hconfig.json")

	fmt.Println(dgSDK, err)

	reqSeqId := time.Now().Unix()
	bsdata := BsPaySdk.V3TradePaymentJspayRequest{
		ReqSeqId:  strconv.Itoa(int(reqSeqId)),
		ReqDate:   (time.Now()).Format(time.DateOnly),
		HuifuId:   "6666000171768967",
		GoodsDesc: "123456",
		TradeType: "A_JSAPI",
		TransAmt:  "0.10",
	}
	bsdata.ExtendInfos = getExtendInfos()
	res, err := dgSDK.V3TradePaymentJspayRequest(bsdata)

	fmt.Println(res, err)
}

/**
 * 非必填字段
 */
func getExtendInfos() map[string]interface{} {
	// 设置非必填字段
	extendInfoMap := make(map[string]interface{})
	// 交易有效期
	extendInfoMap["time_expire"] = "20250922235959"
	// 微信参数集合
	//extendInfoMap["wx_data"] = "{\"sub_appid\":\"wxdfe9a5d141f96685\",\"sub_openid\":\"o8jhotzittQSetZ-N0Yj4Hz91Rqc\",\"detail\":{\"cost_price\":\"43.00\",\"receipt_id\":\"20220628132043853798\",\"goods_detail\":[{\"goods_id\":\"6934572310301\",\"goods_name\":\"太龙双黄连口服液\",\"price\":\"43.00\",\"quantity\":\"1\",\"wxpay_goods_id\":\"12235413214070356458058\"}]}}"
	//// 是否延迟交易
	//extendInfoMap["delay_acct_flag"] = "N"
	//// 分账对象
	//extendInfoMap["acct_split_bunch"] = "{\"acct_infos\":[{\"div_amt\":\"0.10\",\"huifu_id\":\"6666000109133323\"}]}"
	//// 传入分账遇到优惠的处理规则
	//extendInfoMap["term_div_coupon_type"] = "0"
	//// 禁用信用卡标记
	//extendInfoMap["limit_pay_type"] = "NO_CREDIT"
	//// 场景类型
	//extendInfoMap["pay_scene"] = "02"
	//// 安全信息
	//extendInfoMap["risk_check_data"] = "{\"ip_addr\":\"180.167.105.130\",\"base_station\":\"192.168.1.1\",\"latitude\":\"33.3\",\"longitude\":\"33.3\"}"
	//// 设备信息
	//extendInfoMap["terminal_device_data"] = "{\"device_type\":\"1\",\"device_ip\":\"10.10.0.1\",\"device_gps\":\"192.168.0.0\",\"devs_id\":\"SPINTP357338300264411\"}"
	//// 异步通知地址
	extendInfoMap["notify_url"] = "http://www.baidu.com"
	return extendInfoMap
}
